//
//  MyCollectionController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/27.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "MyCollectionController.h"
#import "MyCollectionArticleController.h"
#import "MyCollectionVideoController.h"
#import "MyCollectionSmallVideoController.h"
#import "MyCollectionQuestionAnswerController.h"
#import "MyCollectionFoodController.h"

@interface MyCollectionController ()<SGPageTitleViewDelegate, SGPageContentScrollViewDelegate>
/**标题视图*/
@property (nonatomic,strong)SGPageTitleView*pageTitleView;
/**初始化标题视图配置文件*/
@property (nonatomic,strong)SGPageTitleViewConfigure *configure;
/**子视图切换容器*/
@property (nonatomic,strong)SGPageContentScrollView*pageContentScrollView;
/**<#属性#>*/
@property (nonatomic,strong)NSMutableArray*childArr;
@end

@implementation MyCollectionController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的收藏";
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setupPageView];
}

-(SGPageTitleViewConfigure*)configure{
    if(!_configure){
        _configure=[SGPageTitleViewConfigure pageTitleViewConfigure];
        _configure.titleTextZoom = YES;
        _configure.titleTextZoomRatio = 0.5;
        _configure.titleAdditionalWidth = 30;
        _configure.titleGradientEffect = YES;
        _configure.titleSelectedColor = UIColorFromRGB(0x009966);
        _configure.indicatorColor = UIColorFromRGB(0x009966);
        _configure.titleFont = PingFangSC_Medium(16);
    }
    return _configure;
}

-(SGPageTitleView*)pageTitleView{
    if(!_pageTitleView){
        NSArray *titleArr = @[@"文章", @"视频", @"小视频", @"问答", @"美食"];
        _pageTitleView=[SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, 0, KScreenWidth, 44.0) delegate:self titleNames:titleArr configure:self.configure];
        
    }
    return _pageTitleView;
}
-(SGPageContentScrollView*)pageContentScrollView{
    if(!_pageContentScrollView){
        

        CGFloat ContentCollectionViewHeight = KScreenHeight - CGRectGetMaxY(_pageTitleView.frame) - K_TopHeight;
        _pageContentScrollView=[[SGPageContentScrollView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_pageTitleView.frame), KScreenWidth, ContentCollectionViewHeight)  parentVC:self childVCs:self.childArr];
    _pageContentScrollView.delegatePageContentScrollView= self;
    }
    return _pageContentScrollView;
}
-(NSMutableArray *)childArr{
    if (!_childArr) {
        _childArr =[NSMutableArray array];
        MyCollectionArticleController *oneVC = [[MyCollectionArticleController alloc] init];
        MyCollectionVideoController *twoVC = [[MyCollectionVideoController alloc] init];
        MyCollectionSmallVideoController *threeVC = [[MyCollectionSmallVideoController alloc] init];
        MyCollectionQuestionAnswerController *fourVC = [[MyCollectionQuestionAnswerController alloc] init];
        MyCollectionFoodController *fiveVC = [[MyCollectionFoodController alloc] init];

        NSArray *arr = @[oneVC, twoVC, threeVC, fourVC, fiveVC];
        [_childArr addObjectsFromArray:arr];
        
    }
    return _childArr;
}
- (void)setupPageView {
    
    /// pageTitleView
    [self.view addSubview:self.pageTitleView];
    
    /// pageContentCollectionView
    [self.view addSubview:self.pageContentScrollView];
}

- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
    if (selectedIndex != 1) {
        MyCollectionVideoController *twoVC =self.childArr[1];
        [twoVC pausePlay];
    }
    [self.pageContentScrollView setPageContentScrollViewCurrentIndex:selectedIndex];
}

#pragma mark - SGPageContentScrollViewDelegate
/**
 *  联动 SGPageTitleView 的方法
 *
 *  @param pageContentScrollView      SGPageContentScrollView
 *  @param progress                   SGPageContentScrollView 内部视图滚动时的偏移量
 *  @param originalIndex              原始视图所在下标
 *  @param targetIndex                目标视图所在下标
 */
- (void)pageContentScrollView:(SGPageContentScrollView *)pageContentScrollView
                     progress:(CGFloat)progress
                originalIndex:(NSInteger)originalIndex
                  targetIndex:(NSInteger)targetIndex {
    if (targetIndex != 1) {
        MyCollectionVideoController *twoVC =self.childArr[1];
        [twoVC pausePlay];
    }
    [self.pageTitleView setPageTitleViewWithProgress:progress
                                     originalIndex:originalIndex
                                       targetIndex:targetIndex];
}

@end
